<include file="Public/header" /> 

<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
	<include file="Public/sidebar" /> 
	<!--左侧菜单//-->
	
	<!-- mainCon -->
	<div id="mainCon" class="mainCon">
		<h4>
			角色授权
		</h4>
		<div class="bk10"></div>
		<form class="form-horizontal" id="myform">
			<div class="form-group">
				<label for="name" class="col-sm-2 control-label">角色</label>
				<div class="col-sm-5">
					<input type="text" name="name" class="form-control" value="<{$role['name']}>" id="name" readonly>
				</div>
			</div>
			
			<div class="form-group">
				<label for="name" class="col-sm-2 control-label">权限</label>
				<div class="col-sm-5">
					<div class="bk10"></div>
					<foreach name="right" item="vo" key="key">
						<div>
							<label>
								<input type="checkbox" class="select_k">
								<{$key}>
							</label>
						</div>
						<div>
							<foreach name="vo" item="vvo">
								<label style="font-weight:normal;margin-left:15px">
									<input type="checkbox" name="privilege[]" value="<{$vvo['id']}>" <if condition="in_array($vvo['id'],$_roleprivi)">checked</if> >
									<{$vvo['title']}>
								</label>
							</foreach>
						</div>
					</foreach>
				</div>
			</div>

			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="hidden" name="id" value="<{$role['id']}>">
					<button type="submit" class="btn btn-default col-sm-2">保存</button>
				</div>
			</div>
		</form>
		
	</div>
	<!-- mainCon// -->
	
</div>
<!--主窗体//-->

<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/validate/jquery.validate.min.js"></script>
<script src="__PUBLIC__/js/validate/messages_zh.js"></script>
<script>
$(function(){

	// 选择
	$(".select_k").click(function(){
		if($(this).prop("checked") == true){
			$(this).parents('div').next('div').find("input").prop("checked",true);
		}else{
			$(this).parents('div').next('div').find("input").prop("checked",false);
		}
	});
	
	$("#myform").validate({
		rules: {
			
		},
		messages: {
		
		},
		submitHandler : function(form){
			var ajaxUrl = "<{:U('Admin/Role/right')}>";
			 $.post(ajaxUrl,$(form).serialize(),function(r){
    			if (r.error == 1){
    				layer.alert(r.errmsg,{icon: 2});
    			}else{
    				layer.alert(r.errmsg,{icon: 1},function(){
    					window.location.reload();
    				});
    			}
    			return false;
    		});
        	return false
		}
	});
});
</script>

<include file="Public/footer" /> 